﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;


namespace IFRS.DataAccess.DAL
{
    public class SPR_EIR
    {
        public DataTable SEARCH_ALL(EIR obEIR, Paging paging,bool isAllBranch ,string sCostCenter, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@isAllBranch", isAllBranch));
                lstParams.Add(new SqlParameter("@sCostCenter", sCostCenter));
                lstParams.Add(new SqlParameter("@TransactionDate", obEIR.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@SourceDataID", obEIR.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountNo", obEIR.AccountNo.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_EIR_SEARCHALL", lstParams.ToArray());
                iRecordCount = (int)lstParams[0].Value;


            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int EIRID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@EIRID", EIRID));
                dt = Utility.StoredProcDataTable("SPR_EIR_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(EIR obEIR)
        {

            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@EIRID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@TransactionDate", obEIR.TransactionDate));
                lstParams.Add(new SqlParameter("@SourceDataID", obEIR.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", obEIR.AccountNo));
                lstParams.Add(new SqlParameter("@EIRValue", obEIR.EIRValue));
                lstParams.Add(new SqlParameter("@CreatedDate", obEIR.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", obEIR.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", obEIR.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", obEIR.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", obEIR.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", obEIR.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", obEIR.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", obEIR.UpdatedBranch));

                Utility.ExecuteStoredProc("SPR_EIR_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(EIR obEIR)
        {


            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@EIRID", obEIR.EIRID));
                lstParams.Add(new SqlParameter("@TransactionDate", obEIR.TransactionDate));
                lstParams.Add(new SqlParameter("@SourceDataID", obEIR.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", obEIR.AccountNo));
                lstParams.Add(new SqlParameter("@EIRValue", obEIR.EIRValue));
                lstParams.Add(new SqlParameter("@CreatedDate", obEIR.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", obEIR.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", obEIR.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", obEIR.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", obEIR.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", obEIR.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", obEIR.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", obEIR.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_EIR_UPDATE", lstParams.ToArray());


            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(EIR obEIR)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@EIRID", obEIR.EIRID));
                lstParams.Add(new SqlParameter("@UpdatedDate", obEIR.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", obEIR.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", obEIR.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", obEIR.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_EIR_DELETE", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

    }
}
